import logging
import random
import uuid
from threading import Thread

import cv2

from create_train import CatchPICFromVideo, save_image
from face_train import Model

if __name__ == '__main__':
    model = Model()
    model.load_model(file_path='./model/face.model')
    # test_image = cv2.imread(r"./test/0.jpg")

    test_uuid = uuid.uuid4()
    # CatchPICFromVideo("截取人脸", 0, 10, )

    save_th = Thread(target=save_image)
    crame_th = Thread(target=CatchPICFromVideo, args=("截取人脸", 0, 10, './test/{}'.format(test_uuid)))
    crame_th.start()
    save_th.start()

    save_th.join()

    jpg_index = random.randint(0, 5)
    result = 0
    for i in range(5):
        test_image = cv2.imread(r"./test/{}/{}.jpg".format(test_uuid, jpg_index + i))
        result += model.face_predict(test_image)
        print("result[{}]:{}".format(i, result))
    if result >= 4.2:
        print("验证成功")
    else:
        print("验证失败")
    logging.info(result)
